package com.fanshuai.springcloud.controller;

import com.fanshuai.springcloud.domain.Book;
import com.fanshuai.springcloud.domain.User;
import com.fanshuai.springcloud.web.response.CallResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/web/ribbon")
public class WebController {

    @Resource
    private RestTemplate userRestTemplate;
    @Resource
    private RestTemplate bookRestTemplate;

    @GetMapping("/books")
    public CallResult<List<Book>> bookList() {
        String url = "http://book-service/book/list";
        return bookRestTemplate.getForObject(url, CallResult.class);
    }

    @GetMapping("/users")
    public CallResult<List<User>> userList() {
        String url = "http://user-service/user/list";
        return userRestTemplate.getForObject(url, CallResult.class);
    }
}
